<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:XSWeekDetails="http://rpmestre.net/xscrawler">
	<xsl:namespace-alias stylesheet-prefix="XSWeekDetails" result-prefix="xsl"/>
	<xsl:output method="html" indent="yes"/>
	<xsl:template match="/">
		<html>
			<head>
				<title>XpertStats XSCrawler - Jornadas Liga Zon Sagres</title>
				<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
				<link rel="shortcut icon" href="../imagens/template/logo.ico"/>
				<link rel="icon" type="image/gif" href="../imagens/template/logo.ico"/>
				<script language="JavaScript" src="../calendario.js"/>
				<link href="../style.css" rel="stylesheet" type="text/css"/>
				<link href="../style2.css" rel="stylesheet" type="text/css"/>
				<link href="../menubuttons.css" rel="stylesheet" type="text/css"/>
				<link href="../menu.css" rel="stylesheet" type="text/css"/>
				<link href="../fbstyle.css" rel="stylesheet" type="text/css"/>
			</head>
			<body>
				<div id="wrap">
					<div id="header">
						<div id="headerH">
							<div id="logo">
								<a href="index.php">
									<img src="../imagens/template/logo.png"/>
								</a>
							</div>
						</div>
					</div>
					<div id="menuD">
						<div id="menuB">
							<div id="menu">
								<a class="active">
									<span>XSCRAWLER MENU</span>
								</a>
								<a href="../index.php">
									<span>Home</span>
								</a>
								<a href="/xscrawler/xsweeks.php">
									<span>Actualizar Resultados</span>
								</a>
							</div>
						</div>
					</div>
					<div id="main-col" style="padding-top:10px;">
						<h2 style="padding-bottom:10px">Próximos Jogos</h2>
						<xsl:variable name="teamsMap" select="document('../mapping.xml')"/>
						<xsl:variable name="BFOdds" select="document('../BF.xml')"/>
						<table class="simpletable" style="width:900px;">
							<thead>
								<th>Dia</th>
								<th>Hora</th>
								<th colspan="3">Jogo</th>
								<th colspan="2">Operações</th>
							</thead>
							<tbody>
								<xsl:for-each select="XSWeekDetails:XSWeekDetails/XSWeekDetails:match">
									<xsl:variable name="hostXSId" select="XSWeekDetails:host/@id"/>
									<xsl:variable name="visitorXSId" select="XSWeekDetails:visitor/@id"/>
									<tr style="height:30px">
										<td style="text-align:right; font-size:14px">
											<xsl:value-of select="XSWeekDetails:date"/>
										</td>
										<td style="text-align:right; font-size:14px">
											<xsl:value-of select="concat(substring(XSWeekDetails:hour, 0,3), 'h', substring(XSWeekDetails:hour, 4,2))"/>
										</td>
										<td style="text-align:right; font-size:14px">
											<xsl:value-of select="XSWeekDetails:host"/>
										</td>
										<td style="text-align:center; width:10px">x</td>
										<td style=" font-size:14px">
											<xsl:value-of select="XSWeekDetails:visitor"/>
										</td>
										<xsl:variable name="filePath" select="string(concat('/xscrawler/cache/bfxml/', @id, '.xml'))"/>
										<xsl:variable name="tFile" select="document($filePath)"/>
										<xsl:variable name="tOdds" select="boolean($tFile)"/>
										<xsl:choose>
											<xsl:when test="$tOdds">
												<td/>
												<td style="text-align:center;">
													<a href="{$filePath}">
														<button type="submit" class="facebooked">Ver prognóstico</button>
													</a>
												</td>
											</xsl:when>
											<xsl:otherwise>
												<xsl:variable name="formName" select="concat('f_',@id)"/>
												<form method="post" name="{$formName}" action="gamepreview.php" style="padding:10px;">
													<input type="hidden" name="matchId" value="{@id}"/>
													<td style="padding-right:3px; text-align:right">
														<xsl:variable name="hostBFName" select="$teamsMap/XSWeekDetails:mapping/XSWeekDetails:team_names/XSWeekDetails:team[XSWeekDetails:xs/@id=$hostXSId]/XSWeekDetails:bf"/>
														<xsl:variable name="visitorBFName" select="$teamsMap/XSWeekDetails:mapping/XSWeekDetails:team_names/XSWeekDetails:team[XSWeekDetails:xs/@id=$visitorXSId]/XSWeekDetails:bf"/>
														<select name="bfEventName" style="font-size:10px; ">
															<xsl:for-each select="$BFOdds/betfair/event[contains((@name), $hostBFName) and contains((@name), $visitorBFName)]">
																<option value="{@name}">
																	<xsl:value-of select="@name"/>
																</option>
															</xsl:for-each>
															<xsl:for-each select="$BFOdds/betfair/event[contains((@name), $hostBFName) or contains((@name), $visitorBFName)]">
																<option>
																	<xsl:value-of select="@name"/>
																</option>
															</xsl:for-each>
														</select>
													</td>
													<td style="text-align:center;">
														<button type="button" class="facebooked" onclick="javascript:document.{$formName}.submit()">Associar jogo</button>
													</td>
												</form>
											</xsl:otherwise>
										</xsl:choose>
									</tr>
								</xsl:for-each>
							</tbody>
						</table>
					</div>
				</div>
				<div id="footer">
					<div id="footerD">
						<div id="footerF" class="aligned">
					</div>
						<div id="footerS" class="aligned">XS v1.4 Lite</div>
					</div>
				</div>
			</body>
		</html>
	</xsl:template>
</xsl:stylesheet>
